package dao;

import org.junit.Test;
import pojo.Manager;
import utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author konley
 * @date 2020-06-19 23:44
 */
public class ManagerDao {
    public Manager getManagerById(int id){
        PreparedStatement ps = null;
        ResultSet rs = null;
        Connection con = DBUtils.getConnection();
        Manager manager = null;
        try {
            ps = con.prepareStatement("select * from manager where id=?");
            ps.setInt(1,id);
            rs = ps.executeQuery();
            if(rs.next()){
                manager = new Manager(
                        rs.getInt("id"),
                        rs.getString("password")
                );
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            DBUtils.release(rs,ps,con);
        }
        return manager;
    }

}
